//
//  JSONDictionary.m
//  URLSessionTest
//
//  Created by mac on 2017/7/11.
//  Copyright © 2017年 yyb. All rights reserved.
//

#import "JSONDictionary.h"

@implementation JSONDictionary

+ (NSDictionary *)dictionaryWithJSON:(id)Json {
    if (!Json ||Json == (id) kCFNull  ) {
        return nil;
    }
    NSDictionary *dic = nil;
    NSData *jsonData = nil;
    if ([Json isKindOfClass:[NSDictionary class]]) {
        dic = Json;
    } else if ([Json isKindOfClass:[NSString class]]) {
        jsonData = [(NSString *)Json dataUsingEncoding:NSUTF8StringEncoding];
    } else if ([Json isKindOfClass:[NSData class]]) {
        jsonData = Json;
    }
    if (jsonData) {
        dic = [NSJSONSerialization JSONObjectWithData:jsonData options:kNilOptions error:NULL];
        if (![dic isKindOfClass:[NSDictionary class]]) {
            dic = nil;
        }
    }
    return dic;
}

@end
